﻿@{
    ViewData["Title"] = "添加路径细节详情配置";
    Layout = "_Edit";
}
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-add">
        <input type="hidden" class="input-text" value="@Model.ID" id="id" name="id">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>路径：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="RouteID" id="RouteID" onchange="OnRouteChange()">
                        <option value="">--请选择--</option>
                        @foreach (var item in Model.RouteInfos)
                        {
                            if (Model.RouteID + "" == item.ID)
                            {
                                <option value="@item.ID" selected>@item.RouteInfo</option>
                            }
                            else
                            {
                                <option value="@item.ID">@item.RouteInfo</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>前一节点：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="PrevionsID" id="PrevionsID">
                        <option value="0">--请选择--</option>
                        @*@foreach (var item in Model.StationInfos)
                        {
                            if (Model.ToStation == item.StationCode)
                            {
                                <option value="@item.StationCode" selected>@item.StationName</option>
                            }
                            else
                            {
                                <option value="@item.StationCode">@item.StationName</option>
                            }
                        }*@
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否起始节点：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="radio-box">
                    @if (Model.IsStart)
                    {
                        <input name="IsStart" type="radio" id="IsStart-true" value="1" checked>
                    }
                    else
                    {
                        <input name="IsStart" type="radio" id="IsStart-true"  value="1">
                        
                    }
                        <label for="IsStart-true">是</label>
				</div>
				<div class="radio-box">
                    @if (Model.IsStart)
                    {
                        <input name="IsStart" type="radio" id="IsStart-false" value="0">
                    }
                    else
                    {
                        <input name="IsStart" type="radio" id="IsStart-false" value="0" checked>
                    }
					    <label for="IsStart-false">否</label>
				</div>
			</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否结束节点：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="radio-box">
                    @if (Model.IsEnd)
                    {
                        <input name="IsEnd" type="radio" id="IsEnd-true" value="1" checked>
                    }
                    else
                    {
                        <input name="IsEnd" type="radio" id="IsEnd-true"  value="1">
                        
                    }
                        <label for="IsEnd-true">是</label>
				</div>
				<div class="radio-box">
                    @if (Model.IsEnd)
                    {
                        <input name="IsEnd" type="radio" id="IsEnd-false" value="0">
                    }
                    else
                    {
                        <input name="IsEnd" type="radio" id="IsEnd-false" value="0" checked>
                    }
					    <label for="IsEnd-false">否</label>
				</div>
			</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>调度类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="DispatchType" id="DispatchType">
                        <option value="-1">--请选择--</option>
                        @foreach (var item in Model.DispatchTypes)
                        {
                            if (Model.DispatchTypeId == item.ID)
                            {
                                <option value="@item.ID" selected>@item.Desception</option>
                            }
                            else
                            {
                                <option value="@item.ID">@item.Desception</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>起始设备：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.FromEquipment" placeholder="" id="FromEquipment" name="FromEquipment">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>起始货位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.FromCargo" placeholder="" id="FromCargo" name="FromCargo">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>起始货位列：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.FromCargoColumn" placeholder="" id="FromCargoColumn" name="FromCargoColumn">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>目标设备：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.ToEquipment" placeholder="" id="ToEquipment" name="ToEquipment">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>目标货位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.ToCargo" placeholder="" id="ToCargo" name="ToCargo">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="button" onclick="operate()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

@section javascript{

<script>
    $('.skin-minimal input').iCheck({
         checkboxClass: 'icheckbox-blue',
         radioClass: 'iradio-blue',
         increaseArea: '20%'
     });
     $(function(){
         //var js_routeid = @Model.Js_RouteID;
         //console.log(js_routeid);
         var routeID = $("#RouteID").val();
         console.log(routeID);
         if(routeID != 0){
             loadPrevsions(routeID);
         }
     });

     function loadPrevsions(routeID){
         console.log(routeID);
        $("#PrevionsID").empty();
        $.ajax({
            method: "POST",
            async: false,
            url: "/routedetailinfo/getroutedetailinfobyrouteid",
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            data: {
                routeID : routeID
            },
            success: function(data){
                console.log(data);
                var top = "<option value=\"0\">--请选择--</option>";
                $("#PrevionsID").append(top);
                $.each(data, function(index, item){
                    var op = "<option value=\""+ item.js_ID + "\">" + item.target +"</option>"
                    if(@Model.Js_PrevionsID == item.js_ID + ""){
                        op = "<option value=\""+ item.js_ID + "\" selected>" + item.target +"</option>"
                    }
                    $("#PrevionsID").append(op);
                })
            }

        });
     }

     function OnRouteChange(){
        var routeID = $("#RouteID").val();
        console.log(routeID);
        loadPrevsions(routeID);
     }
     function operate(){
         var RouteID=$("#RouteID").val();
         if(RouteID==null||RouteID=="")
         {
            popupAlert('请选择路径',2,function(data){layer.close(data);});
           return;
         }
         //var PrevionsID=$("#PrevionsID").val();
         //if(PrevionsID==null||PrevionsID=="")
         //{
         //   popupAlert('请选择上一货位',2,function(data){layer.close(data);});
         //  return;
         //}
         var isStart = $("#IsStart").val();
         console.log(isStart);
         var DispatchType=$("#DispatchType").val();
         if(DispatchType==null||DispatchType==""||DispatchType==-1)
         {
            popupAlert('请选择调度类型',2,function(data){layer.close(data);});
           return;
         }
         var FromEquipment=$("#FromEquipment").val();
         if(FromEquipment==null||FromEquipment=="")
         {
            popupAlert('起始设备不能为空',2,function(data){layer.close(data);});
           return;
         }
         var FromCargo=$("#FromCargo").val();
         if(FromCargo==null||FromCargo=="")
         {
            popupAlert('起始货位不能位空',2,function(data){layer.close(data);});
           return;
         }
         var FromCargoColumn=$("#FromCargoColumn").val();
         if(FromCargoColumn==null||FromCargoColumn=="")
         {
            popupAlert('起始货位列不能为空',2,function(data){layer.close(data);});
           return;
         }
         var ToEquipment=$("#ToEquipment").val();
         if(ToEquipment==null||ToEquipment=="")
         {
            popupAlert('目标设备不能为空',2,function(data){layer.close(data);});
           return;
         }
         var ToCargo=$("#ToCargo").val();
         if(ToCargo==null||ToCargo=="")
         {
            popupAlert('目标货位不能为空',2,function(data){layer.close(data);});
           return;
         }
        SubmitFormForAjax("/routedetailinfo/operateroutedetailinfo", $("#form-add").serialize(), function (data) {
            if (data.result) {
                    popupAlert('提交成功',1,function(){closePageLayer(true);});
            }else{
                popupAlert(data.message,2,function(data){layer.close(data);});
            }
        },true);
     }
</script>
}